// app/plugin/tcp/index.js
const TcpServer = require('./server');

module.exports = {
    async apply(app, options) {
        // 创建一个TCP服务器实例并挂载到app上
        app.tcpServer = new TcpServer(app.config.tcp);

        // 在应用启动前启动TCP服务器
        app.beforeStart(async () => {
            await app.tcpServer.start();
            app.logger.info(`TCP Server is listening on port ${app.config.tcp.port}`);
        });

        // 在应用关闭前关闭TCP服务器
        app.beforeClose(async () => {
            await app.tcpServer.stop();
            app.logger.info('TCP Server closed.');
        });
    },
};
